package com.mine.crawler.beans;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

public class MySqlDBCategoryParentTree
{
	MySqlDBCategoryNode root;
	private Logger log = Logger.getLogger(MySqlDBCategoryParentTree.class);

	public MySqlDBCategoryParentTree(String local_root)
	{
		MySqlDBCategoryNode myRootNode = new MySqlDBCategoryNode(local_root);
		root = myRootNode;
	}

	public void addChild(MySqlDBCategoryNode parent, MySqlDBCategoryNode child)
	{
		
	}
	
	public MySqlDBCategoryNode search(MySqlDBCategoryNode toLocate)
	{
		MySqlDBCategoryNode currentNode = root;
		int i=0;
		int nodeIndex = 0;
		List <MySqlDBCategoryNode>children = new ArrayList<MySqlDBCategoryNode>();
		List <Integer>scores = new ArrayList<Integer>();
		int max_weight = 0;
		int temp = 0;
		int childIndex = -1;
		
		while(currentNode!= null)
		{
			if(currentNode.getCategory_name().equalsIgnoreCase(toLocate.getCategory_name()))
			{
				return currentNode;
				//return true;
			}
			else
			{
				children = currentNode.getChildren();
				Iterator<MySqlDBCategoryNode> it = children.iterator();
				
				while(it.hasNext())
				{
					temp = (it.next()).getComplete_cat_name().
						compareTo(toLocate.getComplete_cat_name());
					scores.add(new Integer(temp));
					if(temp > max_weight)
					{	
						max_weight = temp;
						childIndex = childIndex +1;
					}
				}
				
				//scores.indexOf(new Integer(ma_weight));
			}
			
			/*
			nodeIndex = currentNode.getChildren().indexOf(new MySqlDBCategoryNodeLogical(nodeList[i]));
			if(nodeIndex == -1)
			{
				break;
			}
			else
				currentNode = currentNode.getChildren().get(nodeIndex);
			i = i+1; */
		}
		return null;
	}
	
	protected int string_score(String original, String toFind)
	{
		int score = 0;
		//"".
		
		return score;
	}
}
 